package multithreading;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @ClassName MyCallable
 * @Date 2021/7/28 8:45
 * @Author 李明杰
 * @Description Callable实现多线程
 */

public class MyCallable implements Callable {
    @Override
    public Object call() throws Exception {
        return "thread is running";
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        MyCallable myCallable = new MyCallable();
        FutureTask futureTask = new FutureTask<>(myCallable);
        Thread thread = new Thread(futureTask);
        thread.start();
        String result = null;

        //获取线程执行结果
        result = (String) futureTask.get();

        System.out.println(result);
    }

}
